Completed
Push — master ( dc838b...dfb2bc )
by Askupa
01:34
created

Amarkal.settings.sections.activate   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 20
rs 9.4285
1
Amarkal.settings.sections = {
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
    $links: null,
3
    $loader: null,
4
    data: null,
5
    activeSection: null,
6
    prevSection: null,
7
    init: function() {
8
        this.data = JSON.parse($('#sections-config').text());
9
        this.$links = $('.amarkal-settings-sections li');
10
        this.$loader = $('#amarkal-settings-loader');
11
12
        this.initSections();
13
    },
14
    initSections: function() {
15
        if(typeof this.data === 'object' && Object.keys(this.data).length > 0) {
16
            var _this = this;
17
            this.$links.on('click', function(){
18
                _this.activate($(this).attr('data-slug'));
19
            });
20
            this.activateInitialSection();
21
            this.$loader.hide();
22
        }
23
        else {
24
            Amarkal.settings.fields.showAll();
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
        }
26
    },
27
    activateInitialSection: function() {
28
        if('' !== window.location.hash) {
29
            this.activate(window.location.hash.substring(1));
30
        }
31
        else {
32
            this.activate($(this.$links[0]).attr('data-slug'));
33
        }
34
    },
35
    activate: function(sectionSlug) {
36
        if(this.activeSection === sectionSlug) {
37
            return;
38
        }
39
        if(this.activeSection !== null) {
40
            this.prevSection = this.activeSection;
41
        }
42
        this.activeSection = sectionSlug;
43
44
        this.$links
45
            .removeClass('active')
46
            .filter('[data-slug="'+sectionSlug+'"]')
47
            .addClass('active');
48
49
        Amarkal.settings.header.setSectionTitle(this.getTitle(sectionSlug));
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
50
        Amarkal.settings.header.setSectionSubtitle(this.getSubtitle(sectionSlug));
51
        Amarkal.settings.fields.showBySection(sectionSlug);
52
53
        window.location = '#'+sectionSlug;
54
    },
55
    deactivate: function() {
56
        var sectionSlug = this.activeSection;
0 ignored issues
show
Unused Code introduced by
The variable sectionSlug seems to be never used. Consider removing it.
Loading history...
57
        this.$links.removeClass('active');
58
        Amarkal.settings.fields.hideAll();
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
59
        this.activeSection = null;
60
    },
61
    flag: function(type, slug) {
62
        this.$links.filter('[data-slug="'+slug+'"]').addClass('flag-'+type);
63
    },
64
    unflagAll: function() {
65
        this.$links.removeClass('flag-error flag-notice');
66
    },
67
    getTitle: function(slug) {
68
        return this.data[slug].title;
69
    },
70
    getSubtitle: function(slug) {
71
        return this.data[slug].subtitle;
72
    }
73
};